/**
- Copyright (c) 2019 Kagilum SAS.
-
- This file is part of iceScrum.
-
- iceScrum is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License.
-
- iceScrum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with iceScrum.  If not, see <http://www.gnu.org/licenses/>.
-
- Authors:
-
- Vincent Barrier (vbarrier@kagilum.com)
- Nicolas Noullet (nnoullet@kagilum.com)
**/

////////////////////
// General style
////////////////////

$action-list: attach, comment, menu, story, take, task, test, unassign;

.sticky-notes.as-sortable-drag {
  position: absolute !important;
  display: block !important;
}

.sticky-notes-disabled .sticky-note-container {
  button, a {
    pointer-events: none;
    cursor: default;
  }
}

.sticky-note {
  color: $is-sticky-note-text;

  a {
    color: $is-sticky-note-text;
    text-decoration: none;
  }

  .title, .description, .sticky-note-content {
    overflow: hidden;
  }

  .title {
    font-family: $is-font-family-bold;
  }

  .id-icon {
    display: none;
  }

  .sticky-note-state-progress {
    height: 15px;
    position: relative;

    .progress {
      height: 15px;
      background-color: rgba(255, 255, 255, 0.35);
    }

    .progress-bar {
      background-color: white;
    }

    .state {
      position: absolute;
      top: 0;
      font-size: 0.625rem;
      text-align: right;
    }

    .status {
      position: absolute;
      top: 0;
      font-size: 0.625rem;
    }
  }

  .sticky-note-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .action-link {
      display: flex;
    }

    .action-icon {
      @include square-background(0.75rem);
      display: inline-block;
    }
  }

  .badge {
    font-size: 0.75rem;
    margin-left: 0.1875rem;
    padding: 0;

    > .limited {
      display: none;
    }

    > .full {
      display: inline;
    }
  }

  .sticky-note-tags {
    height: 1.6875rem;
    overflow: hidden;

    .tag {
      font-size: 0.625rem;
      background: white;
      border-radius: 0.125rem;
      padding: 0.0625rem 0.1875rem;
      box-shadow: 0 1px 3px 0 rgba(156, 164, 171, 0.62);
      color: $is-sticky-note-text;

      &.invert {
        color: white;
      }
    }

    .badge {
      font-size: 0.625rem;

      > .full {
        display: none;
      }

      > .limited {
        display: inline;
      }
    }
  }

  &.sticky-note-type .sticky-note-type-icon {
    @include rectangle-background(0.8125rem, 0.875rem);
  }
}

////////////////////
// List style
////////////////////

.sticky-notes.list-group {
  position: relative;

  &.as-sortable-drag {
    border-top: solid 1px $is-border-color;
    background: $is-bg-color;
  }

  .sticky-note-container {
    box-shadow: none !important; // Override js style
  }

  .sticky-note {
    background: none !important; // Override js style
    color: $is_text-color;

    a {
      color: $is_text-color;
    }

    .id {
      display: none;
    }

    .id-icon {
      display: block;

      text {
        fill: $is-sticky-note-text;
      }
    }

    .sticky-note-head.id-size-xs .id-icon text {
      font-size: 0.75rem;
    }

    .sticky-note-content {
      .item-values {
        white-space: nowrap;
      }

      .title {
        @include text-truncate;
      }

      .description {
        display: none;
      }
    }

    .sticky-note-state-progress {
      .progress {
        height: 1.125rem;
      }

      .progress, .progress-bar {
        background-color: rgba(104, 117, 131, 0.2);
      }

      .state {
        right: 1.25rem;
        font-size: 0.75rem;
      }

      .status {
        left: 1.25rem;
        font-size: 0.75rem;
      }
    }

    .sticky-note-actions {
      .action {
        .action-icon {
          @include square-background(0.875rem);
        }

        @each $action in $action-list {
          .action-icon-#{$action} {
            background-image: url("action-#{$action}-grey.svg");
          }
        }
      }
    }

    .badge {
      font-size: 0.875rem;
    }

    .sticky-note-tags .badge {
      display: none;
    }

    &.sticky-note-type {
      .sticky-note-type-icon {
        @include rectangle-background(1.0625rem, 1.125rem);
      }

      @each $item-type in (defect, technical, architectural) {
        &.#{$item-type} .sticky-note-type-icon {
          background-image: url("type-#{$item-type}-grey.svg");
        }
      }
    }

    &.invert .id-icon text {
      fill: $is-sticky-note-text-invert;
    }
  }
}

.sticky-notes.list-group:not(.list-group-small) {
  .sticky-note-container {
    padding: 0 $is-spacer-x;
    border-bottom: solid 1px $is-border-color;

    &.is-selected, &:hover {
      z-index: 2;
      border-radius: 0.1875rem;

      &:first-of-type {
        border-top: solid 1px $is-border-color;
      }
    }

    &:hover {
      background: $is-bg-color-ter;
    }

    &.is-selected {
      background: $is-bg-color;
    }

    &:first-of-type {
      border-top: solid 1px transparent;
    }
  }

  &.grey-sticky-notes .sticky-note-container:hover {
    background-color: $is-bg-color;
  }

  .sticky-note {
    padding: 0.3125rem 0;

    > div {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      justify-content: space-between;

      > div {
        flex: 0 0 auto;
        padding: 0 0.625rem;
      }
    }

    .id-icon svg text {
      font-size: 1rem;
    }

    .sticky-note-head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 67px;
      padding-left: 0;
      order: 1;
    }

    .sticky-note-content {
      flex: 1 1 auto;
      display: flex;
      padding: 0;
      flex-direction: column-reverse;
      order: 2;
      width: calc(100% - 180px - 67px);

      .item-values {
        height: 1.3125rem;
        font-size: $is-font-size-sm;
      }

      .title {
        color: $is-text-color-alt;
        font-size: 1.0625rem;
      }
    }

    .sticky-note-state-progress {
      height: 1.125rem;
      width: 180px;
      padding: 0;
      order: 5;
    }

    .sticky-note-actions {
      align-self: flex-start;
      margin-top: 6px;
      width: 180px;
      padding: 0;
      justify-content: space-around;
      order: 3;
    }

    .sticky-note-tags {
      width: calc(100% - 180px);
      padding: 0;
      order: 4;
    }
  }
}

.sticky-notes.list-group.list-group-small {
  .sticky-note {
    padding: 0.1875rem;

    > div {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      justify-content: space-between;

      > div {
        flex: 0 0 auto;
        padding: 0 0.625rem;
        height: 1.625rem;
      }
    }

    .id-icon svg {
      width: 1.1875rem;
      height: 1.1875rem;

      text {
        font-size: 1.0625rem;
      }
    }

    .sticky-note-head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 61px;
      padding-right: 0;
      font-size: 0.6875rem;
      order: 1;
    }

    .sticky-note-content {
      flex: 1 0 60%;
      display: flex;
      padding-top: 0;
      padding-bottom: 0;
      flex-direction: row;
      align-items: center;
      order: 2;

      .item-values {
        height: auto;
        font-size: 0.75rem;
        padding: 0 0.625rem;
        border-left: solid 1px $is-border-color-alt;
        border-right: solid 1px $is-border-color-alt;
      }

      .title {
        color: $is-text-color;
        font-size: 0.9375rem;
        padding-left: 0.625rem;
      }
    }

    .sticky-note-state-progress {
      height: 1.125rem;
      width: 200px;
      order: 5;
    }

    .sticky-note-actions {
      width: 200px;
      justify-content: space-around;
      order: 3;
    }

    .sticky-note-tags {
      order: 4;
      width: calc(100% - 200px);
      margin-top: -4px;
      margin-bottom: 4px;
    }

    &.sticky-note-type .sticky-note-type-icon {
      @include rectangle-background(0.75rem, 0.8125rem);
    }
  }
}

.has-selected .sticky-notes.list-group .sticky-note-container:not(.is-selected):hover {
  background-color: $is-bg-color-ter;
}

////////////////////
// Grid  style
////////////////////

.sticky-notes.grid-group {
  display: flex;
  flex-wrap: wrap;
  position: relative;
  height: 100%;
  align-content: flex-start;
  padding: ($is-spacer-x - $is-sticky-note-spacer);

  .sticky-note-container, .as-sortable-placeholder {
    margin: $is-sticky-note-spacer;
  }

  &.sticky-notes-standalone {
    padding: 15px 0 5px 0;

    .sticky-note-container {
      margin: 0;
    }
  }

  .sticky-note-container:not(.is-selected):not(:hover) {
    box-shadow: none !important; // Override js style
  }

  .sticky-note {
    position: relative;

    .sticky-note-state-progress {
      position: absolute;
      bottom: 0;
      right: 0;
      left: 0;

      .state {
        right: 0.5rem;

        &.state-hover-progress {
          color: $is-sticky-note-text;
        }
      }

      .status {
        left: 0.5rem;
      }
    }

    .item-values {
      font-size: 0.625rem;
    }

    &:hover {
      .sticky-note-actions {
        > .action * {
          opacity: 1;
          visibility: visible;
        }
      }

      .sticky-note-content.has-description .title {
        display: none;
      }
    }

    .sticky-note-content {
      .description {
        display: none;
      }

      .item-values {
        height: 15px;
      }
    }

    .sticky-note-actions .action {
      > * {
        opacity: 0.6;
        visibility: hidden;
      }

      &.active {
        > * {
          visibility: visible;
        }
      }

      @each $action in $action-list {
        .action-icon-#{$action} {
          background-image: url("action-#{$action}-black.svg");
        }
      }
    }

    &.invert {
      color: $is-sticky-note-text-invert;

      a {
        color: $is-sticky-note-text-invert;
      }

      .sticky-note-actions .action {
        @each $action in $action-list {
          .action-icon-#{$action} {
            background-image: url("action-#{$action}-white.svg");
          }
        }
      }
    }
  }

  .sticky-note-feature {
    width: $is-feature-width;
    height: $is-feature-height;

    .sticky-note {
      padding: 0.5625rem;
      width: $is-feature-width;
      height: $is-feature-height;
      border-radius: 0.375rem;

      &:hover .sticky-note-content.has-description .item-values {
        display: none;
      }

      .sticky-note-head {
        display: flex;
        justify-content: space-between;
        flex-direction: row-reverse;
        line-height: 1;

        .id {
          font-size: 0.75rem;
        }
      }

      .sticky-note-content {
        margin-top: 4px;
        margin-bottom: 2px;
        height: 70px;

        .item-values {
          margin-bottom: 2px;
        }

        .title {
          font-size: 0.9375rem;
          line-height: 1.17;
          height: 3.51em;
          @include text-truncate-multiline(3);
        }
      }

      .sticky-note-actions {
        justify-content: space-evenly;
      }

      &.sticky-note-type.architectural .sticky-note-type-icon {
        background-image: url("type-architectural-black.svg");
      }

      &.invert.sticky-note-type.architectural .sticky-note-type-icon {
        background-image: url("type-architectural-white.svg");
      }

      .progress {
        border-radius: 0 0 0.25rem 0.25rem; // TODO this is a big hack with a different radius to hide color bleeding, see https://bugs.chromium.org/p/chromium/issues/detail?id=491574
      }

      &:hover .sticky-note-content.has-description .description {
        font-size: 0.75rem;
        line-height: 1.17;
        height: 5.85em;
        @include text-truncate-multiline(5);
      }
    }
  }

  .sticky-note-story {
    width: $is-story-width;
    height: $is-story-heigth;

    &.sticky-note-container:not(.is-selected):not(:hover) {
      box-shadow: -1px 2px 2px -1px rgba(0, 0, 0, 0.05) !important; // Override js style
    }

    .sticky-note {
      padding: 0.5625rem;
      width: $is-story-width;
      height: $is-story-heigth;
      -webkit-clip-path: polygon(0 0, calc(100% - 30px) 0, 100% 30px, 100% 100%, 0 100%);
      clip-path: polygon(0 0, calc(100% - 30px) 0, 100% 30px, 100% 100%, 0 100%);

      &.sticky-note-type .sticky-note-type-icon {
        position: absolute;
        top: 3px;
        right: 33px;
        z-index: 2;
      }

      &:after {
        content: "";
        position: absolute;
        top: 0;
        right: 0;
        border: 15px solid;
        border-color: rgba(255, 255, 255, 0.97);
        z-index: 1;
      }

      .sticky-note-head {
        .id {
          position: absolute;
          left: 151px;
          top: 13px;
          z-index: 2;
          color: #687583;
          font-size: 0.75rem;
        }

        &.id-size-sm .id {
          left: 149px;
          top: 15px;
        }

        &.id-size-xs .id {
          left: 149px;
          font-size: 0.5625rem;
          top: 18px;
        }
      }

      .sticky-note-content {
        height: 102px;
        margin-top: 6px;

        .item-values {
          margin-bottom: 1px;

          .acceptance-test-icon {
            display: inline-block;
            margin-bottom: -2px; // Hack
            @include square-background(0.75rem);
          }

          @each $acceptance-test-state in $acceptance-test-states {
            .acceptance-test-icon-#{$acceptance-test-state} {
              background-image: url("acceptanceTest-#{$acceptance-test-state}-black.svg");
            }
          }
        }

        .title {
          font-size: 0.9375rem;
          line-height: 1.17;
          height: 5.85em; // 5 lines (= 1.17 * 5)
          @include text-truncate-multiline(5);
        }
      }

      .sticky-note-tags {
        margin-bottom: 2px;
      }

      &.sticky-note-type {
        @each $item-type in (defect, technical) {
          &.#{$item-type} {
            .sticky-note-type-icon {
              background-image: url("type-#{$item-type}-black.svg");
            }

            &.invert .sticky-note-type-icon {
              background-image: url("type-#{$item-type}-white.svg");
            }
          }
        }
      }

      &.invert .sticky-note-content .item-values {
        @each $acceptance-test-state in $acceptance-test-states {
          .acceptance-test-icon-#{$acceptance-test-state} {
            background-image: url("acceptanceTest-#{$acceptance-test-state}-white.svg");
          }
        }
      }

      &:hover .sticky-note-content.has-description .description {
        font-size: 0.75rem;
        padding-top: 0.3em;
        line-height: 1.17;
        height: 7.32em; // 6 lines (= 1.17 * 6 + 0.3)
        @include text-truncate-multiline(6);
      }
    }
  }

  &.grey-sticky-notes .sticky-note-story .sticky-note:after {
    border-color: white;
  }

  .sticky-note-task {
    width: $is-task-width;
    height: $is-task-height;

    .sticky-note {
      padding: 0.375rem;
      width: $is-task-width;
      height: $is-task-height;
      border-radius: 0.375rem;

      .sticky-note-head {
        display: flex;
        flex-direction: row-reverse;
        justify-content: space-between;
        margin-bottom: 5px;

        .id {
          padding-right: 2px;
          line-height: 1.0625rem;
          font-size: 0.8125rem;
        }

        .responsible {
          height: 1.0625rem;
        }
      }

      .sticky-note-content {
        padding-left: 1px;
        padding-right: 1px;
        height: 49px;

        .title {
          line-height: 1.17;
          height: 28px;
          font-size: 0.75rem;
          @include text-truncate-multiline(2);
        }
      }

      .sticky-note-tags {
        padding-left: 1px;
        padding-right: 1px;
        margin-bottom: 0.4375rem;
      }

      &.task-blocked:after {
        content: "";
        position: absolute;
        top: -13px;
        right: -12px;
        display: block;
        @include square-background(1.5rem);
        background-image: url("badge-task-blocked.svg");
      }
    }

    &:hover .sticky-note-content.has-description .description {
      padding-top: 0.1875rem;
      line-height: 1.1;
      font-size: 0.625rem;
      height: 44px;
      @include text-truncate-multiline(3);
    }
  }
}

.has-selected .sticky-notes.grid-group .sticky-note-container {
  &.is-selected {
    z-index: 2;
  }

  &:not(.is-selected):hover {
    z-index: 2;
    opacity: 0.75;
  }
}

////////////////////
// Grid  SM
////////////////////

.sticky-notes.grid-group.size-sm {
  .sticky-note-story {
    width: $is-story-width-sm;
    height: $is-story-heigth-sm;

    .sticky-note {
      width: $is-story-width-sm;
      height: $is-story-heigth-sm;

      .sticky-note-head {
        .id {
          left: 131px;
        }

        &.id-size-sm .id {
          left: 129px;
          top: 15px;
        }

        &.id-size-xs .id {
          left: 129px;
          font-size: 0.5625rem;
          top: 18px;
        }
      }

      .sticky-note-content {
        height: 60px;

        .title {
          font-size: 0.875rem;
          line-height: 1.1;
          height: 3.3em;
          @include text-truncate-multiline(3);
        }

        .description {
          display: none !important;
        }
      }

      &:hover .sticky-note-content.has-description .title {
        vertical-align: top;
        display: -webkit-box;
      }
    }

    .sticky-note-tags {
      height: 1.5rem;
      line-height: 1.3;
      margin-bottom: 0;
    }

    .sticky-note-state-progress {
      height: 12px;

      .progress {
        height: 12px;
      }

      .status {
        opacity: 0;
      }

      .state, .status {
        top: -2px;
      }
    }
  }
}

////////////////////
// Light
////////////////////

.sticky-note-container.sticky-note-story.sticky-note-story-light .sticky-note {
  pointer-events: none;
}